<?php

namespace Admin\Controller;

use Think\AjaxPage;
use Think\Page;

class BankController extends BaseController {

    /**
     * 会员资金明细
     */
    public function account_log() {
        $this->display();
    }

    public function account_log_ajax() {
        $timegap = I('timegap');
        // 搜索条件
        $condition = array();
        I('account') ? $condition['account'] = I('account') : false;
        I('email') ? $condition['email'] = I('email') : false;
        I('mobile') ? $condition['mobile'] = I('mobile') : false;
        if (I('timegap')) {
            $gap = explode(' - ', $timegap);
            $begin = $gap[0];
            $end = $gap[1];
            $condition['change_time'] = array('between', array(strtotime($begin), strtotime($end)+24*3600));
        }
        if ($condition['mobile'] != '' || $condition['email'] != '' || $condition['account'] != '') {
            $user_id = M('users')->where("account='{$condition['account']}' OR email='{$condition['email']}' OR mobile='{$condition['mobile']}'")->field('user_id')->find();
            if ($user_id) {
                $condition['user_id'] = $user_id['user_id'];
            }
        }
        $sort_order = I('order_by', 'log_id') . ' ' . I('sort', 'desc');

        $model = M('account_log');
        $count = $model->where($condition)->count();
        $Page = new AjaxPage($count, 10);
        //  搜索条件下 分页赋值
        foreach ($condition as $key => $val) {
            $Page->parameter[$key] = urlencode($val);
        }
        $userList = $model->where($condition)->order($sort_order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
        foreach ($userList as &$v) {
            $grade = M('users')->where(array('user_id' => $v['user_id']))->field('account,email,mobile,nickname')->find();
            $v['account'] = $grade['account'];
            $v['email'] = $grade['email'];
            $v['mobile'] = $grade['mobile'];
            $v['nickname'] = $grade['nickname'];
        }

        $user_id_arr = get_arr_column($userList, 'user_id');
        $show = $Page->show();
        $this->assign('userList', $userList);
        $this->assign('page', $show); // 赋值分页输出
        $this->display();
    }

    /**
     * 导出会员资金明细表格
     */
    public function export_account_log() {
        $sql = "select * from __PREFIX__account_log order by log_id desc";
        $orderList = D()->query($sql);
        $strTable = '<table width="500" border="1">';
        $strTable .= '<tr>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:100px;">序号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:160px;">变动时间</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:160px;">呢称</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">会员号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">手机号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">邮箱号</td>';
        if (tpCache('zfuwl.is_u1') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u1') . '</td>';
        }
        if (tpCache('zfuwl.is_u2') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u2') . '</td>';
        }
        if (tpCache('zfuwl.is_u3') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u3') . '</td>';
        }
        if (tpCache('zfuwl.is_u4') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u4') . '</td>';
        }
        if (tpCache('zfuwl.is_u5') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u5') . '</td>';
        }
        $strTable .= '<td style="text-align:center;font-size:12px;width:200px;">描述</td>';
        $strTable .= '</tr>';
        if (is_array($orderList)) {
            foreach ($orderList as $k => $val) {
                $strTable .= '<tr>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['log_id'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . date("Y-m-d H:i:s", $val['change_time']) . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('nickname') . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('account') . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('mobile') . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('email') . '</td>';
                if (tpCache('zfuwl.is_u1') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['user_money'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u2') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['zuce_money'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u3') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['pay_points'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u4') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['fund_money'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u5') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['frozen_money'] . ' </td>';
                }
                $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['desc'] . ' </td>';
                $strTable .= '</tr>';
            }
        }
        $strTable .='</table>';
        unset($orderList);
        downloadExcel($strTable, '会员资金收支明细');
        exit();
    }



     /**
     * 会员资金明细
     */
    public function account_hz_log() {
        $this->display();
    }

    public function account_hz_log_ajax() {
        $timegap = I('timegap');
        // 搜索条件
        $condition = array();
        I('account') ? $condition['account'] = I('account') : false;
        I('email') ? $condition['email'] = I('email') : false;
        I('mobile') ? $condition['mobile'] = I('mobile') : false;
        $condition['is_hz']=1;
        if (I('timegap')) {
            $gap = explode(' - ', $timegap);
            $begin = $gap[0];
            $end = $gap[1];
            $condition['change_time'] = array('between', array(strtotime($begin), strtotime($end)+24*3600));
        }
        if ($condition['mobile'] != '' || $condition['email'] != '' || $condition['account'] != '') {
            $user_id = M('users')->where("account='{$condition['account']}' OR email='{$condition['email']}' OR mobile='{$condition['mobile']}'")->field('user_id')->find();
            if ($user_id) {
                $condition['user_id'] = $user_id['user_id'];
            }
        }
        $sort_order = I('order_by', 'log_id') . ' ' . I('sort', 'desc');
        $model = M('account_log');
        $count = $model->where($condition)->count();
        $Page = new AjaxPage($count, 10);
        //  搜索条件下 分页赋值
        foreach ($condition as $key => $val) {
            $Page->parameter[$key] = urlencode($val);
        }
        $userList = $model->where($condition)->order($sort_order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
        foreach ($userList as &$v) {
            $grade = M('users')->where(array('user_id' => $v['user_id']))->field('account,email,mobile,nickname')->find();
            $v['account'] = $grade['account'];
            $v['email'] = $grade['email'];
            $v['mobile'] = $grade['mobile'];
            $v['nickname'] = $grade['nickname'];
        }

        $user_id_arr = get_arr_column($userList, 'user_id');
        $show = $Page->show();
        $this->assign('userList', $userList);
        $this->assign('page', $show); // 赋值分页输出
        $this->display();
    }

    /**
     * 导出会员资金明细表格
     */
    public function export_account_hz_log() {
        $sql = "select * from __PREFIX__account_log order by log_id desc where is_hz=1";
        $orderList = D()->query($sql);
        $strTable = '<table width="500" border="1">';
        $strTable .= '<tr>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:100px;">序号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:160px;">变动时间</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:160px;">呢称</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">会员号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">手机号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">邮箱号</td>';
        if (tpCache('zfuwl.is_u1') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u1') . '</td>';
        }
        if (tpCache('zfuwl.is_u2') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u2') . '</td>';
        }
        if (tpCache('zfuwl.is_u3') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u3') . '</td>';
        }
        if (tpCache('zfuwl.is_u4') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u4') . '</td>';
        }
        if (tpCache('zfuwl.is_u5') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u5') . '</td>';
        }
        $strTable .= '<td style="text-align:center;font-size:12px;width:200px;">描述</td>';
        $strTable .= '</tr>';
        if (is_array($orderList)) {
            foreach ($orderList as $k => $val) {
                $strTable .= '<tr>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['log_id'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . date("Y-m-d H:i:s", $val['change_time']) . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('nickname') . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('account') . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('mobile') . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('email') . '</td>';
                if (tpCache('zfuwl.is_u1') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['user_money'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u2') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['zuce_money'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u3') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['pay_points'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u4') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['fund_money'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u5') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['frozen_money'] . ' </td>';
                }
                $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['desc'] . ' </td>';
                $strTable .= '</tr>';
            }
        }
        $strTable .='</table>';
        unset($orderList);
        downloadExcel($strTable, '会员资金收支明细');
        exit();
    }





    /**
     * 会员日收入资金明细
     */
    public function account_day_log() {
        $this->display();
    }

    public function account_day_log_ajax() {
        $timegap = I('timegap');
        // 搜索条件
        $condition = array();
        I('account') ? $condition['account'] = I('account') : false;
        I('email') ? $condition['email'] = I('email') : false;
        I('mobile') ? $condition['mobile'] = I('mobile') : false;
        if (I('timegap')) {
            $gap = explode(' - ', I('timegap'));
            $begin = $gap[0];
            $end = $gap[1];
            $condition['zf_time'] = array('between', array(strtotime($begin), strtotime($end)));
        }
        if ($condition['mobile'] != '' || $condition['email'] != '' || $condition['account'] != '') {
            $user_id = M('users')->where("account='{$condition['account']}' OR email='{$condition['email']}' OR mobile='{$condition['mobile']}'")->field('user_id')->find();
            if ($user_id) {
                $condition['user_id'] = $user_id['user_id'];
            }
        }
        $sort_order = I('order_by', 'log_id') . ' ' . I('sort', 'desc');
        $model = M('account_log');
        $count = $model->where($condition)->count();
        $Page = new AjaxPage($count, 10);
        //  搜索条件下 分页赋值
        foreach ($condition as $key => $val) {
            $Page->parameter[$key] = urlencode($val);
        }

        $userList = $model->where($condition)->order($sort_order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
        foreach ($userList as &$v) {
            $grade = M('users')->where(array('user_id' => $v['user_id']))->field('account,mobile')->find();
            $v['account'] = $grade['account'];
            //$v['email'] = $grade['email'];
            $v['mobile'] = $grade['mobile'];
            //$v['nickname'] = $grade['nickname'];
        }

        $user_id_arr = get_arr_column($userList, 'user_id');
        $show = $Page->show();
        $this->assign('userList', $userList);
        $this->assign('page', $show); // 赋值分页输出
        $this->display();
    }

    /**
     * 导出会员日收入明细表格
     */
    public function export_account_day_log() {
        $sql = "select * from __PREFIX__account_day_log order by id desc";
        $orderList = D()->query($sql);
        $strTable = '<table width="500" border="1">';
        $strTable .= '<tr>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:100px;">序号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:160px;">日期</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:160px;">呢称</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">会员号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">手机号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">邮箱号</td>';
        if (tpCache('zfuwl.is_m1') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.m1') . '</td>';
        }
        if (tpCache('zfuwl.is_m2') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.m2') . '</td>';
        }
        if (tpCache('zfuwl.is_m3') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.m3') . '</td>';
        }
        if (tpCache('zfuwl.is_m4') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.m4') . '</td>';
        }
        if (tpCache('zfuwl.is_m5') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.m5') . '</td>';
        }
        if (tpCache('zfuwl.is_m6') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.m6') . '</td>';
        }
        if (tpCache('zfuwl.is_m7') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.m7') . '</td>';
        }
        if (tpCache('zfuwl.is_m8') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.m8') . '</td>';
        }
        if (tpCache('zfuwl.is_m9') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.m9') . '</td>';
        }
        $strTable .= '<td style="text-align:center;font-size:12px;width:200px;">累计收入</td>';
        $strTable .= '</tr>';
        if (is_array($orderList)) {
            foreach ($orderList as $k => $val) {
                $strTable .= '<tr>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['id'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . date('Y-m-d', $val['zf_time']) . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('nickname') . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('account') . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('mobile') . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('email') . '</td>';
                if (tpCache('zfuwl.is_m1') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money1'] . ' </td>';
                }
                if (tpCache('zfuwl.is_m2') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money2'] . ' </td>';
                }
                if (tpCache('zfuwl.is_m3') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money3'] . ' </td>';
                }
                if (tpCache('zfuwl.is_m4') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money4'] . ' </td>';
                }
                if (tpCache('zfuwl.is_m5') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money5'] . ' </td>';
                }
                if (tpCache('zfuwl.is_m6') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money6'] . ' </td>';
                }
                if (tpCache('zfuwl.is_m7') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money7'] . ' </td>';
                }
                if (tpCache('zfuwl.is_m8') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money8'] . ' </td>';
                }
                if (tpCache('zfuwl.is_m9') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money9'] . ' </td>';
                }
                $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money_total'] . ' </td>';
                $strTable .= '</tr>';
            }
        }
        $strTable .='</table>';
        unset($orderList);
        downloadExcel($strTable, '会员日收支明细');
        exit();
    }

    /**
     * 会员总收入资金明细
     */
    public function account_total_log() {
        $this->display();
    }

    public function account_total_log_ajax() {
        $timegap = I('timegap');
        // 搜索条件
        $condition = array();
        I('account') ? $condition['account'] = I('account') : false;
        I('email') ? $condition['email'] = I('email') : false;
        I('mobile') ? $condition['mobile'] = I('mobile') : false;
        if (I('timegap')) {
            $gap = explode(' - ', $timegap);
            $begin = $gap[0];
            $end = $gap[1];
            $condition['change_time'] = array('between', array(strtotime($begin), strtotime($end)));
        }
        if ($condition['mobile'] != '' || $condition['email'] != '' || $condition['account'] != '') {
            $user_id = M('users')->where("account='{$condition['account']}' OR email='{$condition['email']}' OR mobile='{$condition['mobile']}'")->field('user_id')->find();
            if ($user_id) {
                $condition['user_id'] = $user_id['user_id'];
            }
        }

        $sort_order = I('order_by', 'log_id') . ' ' . I('sort', 'desc');
        if ($timegap) {
            $gap = explode(' - ', $timegap);
            $begin = $gap[0];
            $end = $gap[1];
            $condition['change_time'] = array('between', array(strtotime($begin), strtotime($end)));
        }
        $model = M('account_total_log');
        $count = $model->where($condition)->count();
        $Page = new AjaxPage($count, 10);
        //  搜索条件下 分页赋值
        foreach ($condition as $key => $val) {
            $Page->parameter[$key] = urlencode($val);
        }

        $userList = $model->where($condition)->order($sort_order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
        foreach ($userList as &$v) {
            $grade = M('users')->where(array('user_id' => $v['user_id']))->field('account,email,mobile,nickname')->find();
            $v['account'] = $grade['account'];
            $v['email'] = $grade['email'];
            $v['mobile'] = $grade['mobile'];
            $v['nickname'] = $grade['nickname'];
        }

        $user_id_arr = get_arr_column($userList, 'user_id');
        $show = $Page->show();
        $this->assign('userList', $userList);
        $this->assign('page', $show); // 赋值分页输出
        $this->display();
    }

    /**
     * 导出会员累计总收入明细表格
     */
    public function export_account_total_log() {
        $sql = "select * from __PREFIX__account_total_log order by id desc";
        $orderList = D()->query($sql);
        $strTable = '<table width="500" border="1">';
        $strTable .= '<tr>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:100px;">序号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">会员号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">手机号</td>';
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">库存积分 </td>';
      
 
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">电子积分</td>';
        

            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">福利积分</td>';
       
    
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">分享积分</td>';
      
    
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">事项</td>';
       
        
        $strTable .= '<td style="text-align:center;font-size:12px;width:200px;">累计收入</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:200px;">累计提现</td>';
        $strTable .= '</tr>';
        if (is_array($orderList)) {
            foreach ($orderList as $k => $val) {
                $strTable .= '<tr>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['id'] . '</td>';
              
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('account') . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . M('users')->where('user_id=' . $val['user_id'])->getField('mobile') . '</td>';
              
              
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['user_money'] . ' </td>';
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['zuce_money'] . ' </td>';
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['pay_points'] . ' </td>';
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['share_points'] . ' </td>';
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money1'] . ' </td>';
              
               
                $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['money_total'] . ' </td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['tk_money_total'] . ' </td>';
                $strTable .= '</tr>';
            }
        }
        $strTable .='</table>';
        unset($orderList);
        downloadExcel($strTable, '会员累计总收入明细');
        exit();
    }

    /**
     * 会员资金余额明细
     */
    public function user_money_list() {
        $this->display();
    }

    public function user_money_list_ajax() {
        // 搜索条件
        $condition = array();
        I('account') ? $condition['account'] = array('like', '%' . I('account') . '%') : false;
        $sort_order = I('order_by', 'user_id') . ' ' . I('sort', 'desc');

        $model = M('users');
        $count = $model->where($condition)->count();
        $Page = new AjaxPage($count, 10);
        //  搜索条件下 分页赋值
        foreach ($condition as $key => $val) {
            $Page->parameter[$key] = urlencode($val);
        }

        $userList = $model->where($condition)->order($sort_order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $user_id_arr = get_arr_column($userList, 'user_id');
        $show = $Page->show();
        $this->assign('userList', $userList);
        $this->assign('page', $show); // 赋值分页输出
        $this->display();
    }

    // 导出 表格
    public function export_user_money_list() {
        $sql = "select * from __PREFIX__users order by user_id desc";
        $orderList = D()->query($sql);
        $strTable = '<table width="500" border="1">';
        $strTable .= '<tr>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">序号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:160px;">呢称</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">会员号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">手机号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">邮箱号</td>';
        if (tpCache('zfuwl.is_u1') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u1') . '</td>';
        }
        if (tpCache('zfuwl.is_u2') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u2') . '</td>';
        }
        if (tpCache('zfuwl.is_u3') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u3') . '</td>';
        }
        if (tpCache('zfuwl.is_u4') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u4') . '</td>';
        }
        if (tpCache('zfuwl.is_u5') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u5') . '</td>';
        }
        if (tpCache('zfuwl.is_u6') == 1) {
            $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">' . tpCache('zfuwl.u6') . '</td>';
        }
        $strTable .= '</tr>';
        if (is_array($orderList)) {
            foreach ($orderList as $k => $val) {
                $strTable .= '<tr>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['user_id'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['nickname'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['account'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['mobile'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['email'] . '</td>';
                if (tpCache('zfuwl.is_u1') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['user_money'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u2') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['zuce_money'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u3') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['pay_points'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u4') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['fund_money'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u5') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['total_amount'] . ' </td>';
                }
                if (tpCache('zfuwl.is_u6') == 1) {
                    $strTable .= '<td style="text-align:center;font-size:12px;">' . $val['frozen_money'] . ' </td>';
                }
                $strTable .= '</tr>';
            }
        }
        $strTable .='</table>';
        unset($orderList);
        downloadExcel($strTable, '会员余额管理列表');
        exit();
    }

    /**
     * 银行账户列表
     */
    public function bank_list() {
        $this->list = D('Bank')->select();
        $this->display();
    }

    /**
     * 添加银行账户操作
     */
    public function bank_add() {
        $this->display('bank/add');
    }

    /**
     * 编辑银行账户信息
     */
    public function bank_edit() {
        $this->list = M('bank')->find($_GET['id']);
        $this->display('bank/add');
    }

    /**
     * 添加或修改银行账户操作
     */
    public function add() {
        if ($_POST['id'] > 0) {
            $res = M('bank')->where(array('id' => $_POST['id']))->save($_POST);
            if ($res) {
                $this->success('修改成功', "bank_list");
            } else {
                $this->error('修改失败');
            }
        } else {
            $res = M('bank')->add($_POST);
            if ($res) {
                $this->success('添加成功', 'bank_list');
            } else {
                $this->error('添加失败');
            }
        }
    }

    /**
     * 删除银行账户信息
     */
    public function bank_del() {
        $res = M('bank')->delete($_GET['id']);
        if ($res) {
            $this->success('删除成功');
        } else {
            $this->error('删除失败');
        }
    }

    /**
     * 会员提现列表—— 投资积分
     */
    public function money5_tikuan() {
        $this->display();
    }

    public function money5_tikuan_ajax() {
        // 搜索条件
        $condition = array();
        I('account') ? $condition['account'] = array('like', '%' . I('account') . '%') : false;
        I('status') ? $condition['status'] = I('status') : false;
        $condition['type'] = 0;
        $sort_order = I('order_by', 'id') . ' ' . I('sort', 'desc');

        $model = M('withdrawals');
        $count = $model->where($condition)->count();
        $Page = new AjaxPage($count, 10);
        //  搜索条件下 分页赋值
        foreach ($condition as $key => $val) {
            $Page->parameter[$key] = urlencode($val);
        }

        $tkList = $model->where($condition)->order($sort_order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $show = $Page->show();
        $this->assign('tkList', $tkList);
        $this->assign('page', $show); // 赋值分页输出
        $this->display();
    }

    // 导出 表格  提现列表—— 投资积分
    public function export_money5_tikuan() {
        $sql = "select * from __PREFIX__withdrawals where type = 0 order by user_id desc ";
        $orderList = D()->query($sql);
        $strTable = '<table width="500" border="1">';
        $strTable .= '<tr>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">id</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">会员帐号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">提现时间</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">金额</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">开户行</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">分行支行</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">银行帐号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">状态</td>';
        $strTable .= '</tr>';
        if (is_array($orderList)) {
            foreach ($orderList as $k => $val) {
                switch ($val['status']) {
                    case 0:
                        $b = '提现申请中';
                        break;
                    case 1:
                        $b = '提现成功';
                        break;
                    case 2:
                        $b = '提现失败';
                        break;
                }
                $strTable .= '<tr>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['id'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['account'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . date('Y-m-d H:i:s', $val['create_time']) . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['money'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $a . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['bank_opening'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['bank_address'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['bank_account'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $b . '</td>';
                $strTable .= '</tr>';
            }
        }
        $strTable .='</table>';
        unset($orderList);
        downloadExcel($strTable, '会员提现提现列表');
        exit();
    }

    /**
     * 会员提现列表—— 奖金积分
     */
    public function money6_tikuan() {
        $this->display();
    }

    public function money6_tikuan_ajax() {
        // 搜索条件
        $condition = array();
        I('account') ? $condition['account'] = array('like', '%' . I('account') . '%') : false;
        I('status') ? $condition['status'] = I('status') : false;
        $condition['type'] = 1;
        $sort_order = I('order_by', 'id') . ' ' . I('sort', 'desc');

        $model = M('withdrawals');
        $count = $model->where($condition)->count();
        $Page = new AjaxPage($count, 10);
        //  搜索条件下 分页赋值
        foreach ($condition as $key => $val) {
            $Page->parameter[$key] = urlencode($val);
        }

        $tkList = $model->where($condition)->order($sort_order)->limit($Page->firstRow . ',' . $Page->listRows)->select();
        $show = $Page->show();
        $this->assign('tkList', $tkList);
        $this->assign('page', $show); // 赋值分页输出
        $this->display();
    }

    // 导出 表格  提现列表—— 奖金积分
    public function export_money6_tikuan() {
        $sql = "select * from __PREFIX__withdrawals where type = 1 order by user_id desc ";
        $orderList = D()->query($sql);
        $strTable = '<table width="500" border="1">';
        $strTable .= '<tr>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">id</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">会员帐号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">提现时间</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;width:120px;">金额</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="100">提现类型</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">开户行</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">分行支行</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">银行帐号</td>';
        $strTable .= '<td style="text-align:center;font-size:12px;" width="*">状态</td>';
        $strTable .= '</tr>';
        if (is_array($orderList)) {
            foreach ($orderList as $k => $val) {
                switch ($val['type']) {
                    case 0:
                        $a = '投资积分';
                        break;
                    case 1:
                        $a = '奖金积分';
                        break;
                }
                switch ($val['status']) {
                    case 0:
                        $b = '提现申请中';
                        break;
                    case 1:
                        $b = '提现成功';
                        break;
                    case 2:
                        $b = '提现失败';
                        break;
                }
                $strTable .= '<tr>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['id'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['account'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . date('Y-m-d H:i:s', $val['create_time']) . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['money'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $a . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['bank_opening'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['bank_address'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $val['bank_account'] . '</td>';
                $strTable .= '<td style="text-align:center;font-size:12px;">&nbsp;' . $b . '</td>';
                $strTable .= '</tr>';
            }
        }
        $strTable .='</table>';
        unset($orderList);
        downloadExcel($strTable, '奖金积分提现列表');
        exit();
    }

    //拒绝提现记录
    public function tikuan_jujue() {
        $id = I('id', '');
        $list = M('withdrawals')->where('id=' . I('id'))->find();
        $res = D('withdrawals')->where('id=' . I('id'))->save(array('status' => 2, 'remark' => '审核失败'));
        if ($res) {
            $money = $list['money'] + $list['poundage'];
            accountLog($list['user_id'], '+' . $money, 0, '提现审核失败', 0);

            $this->success("提交成功!");
        } else {
            $this->error("提交失败 请重新操作!");
        }
    }

    //确认提现记录
    public function tikuan_qr() {
        $id = I('id', '');
        $list = M('withdrawals')->where('id=' . I('id'))->find();
        $res = M('withdrawals')->where('id=' . I('id'))->save(array('status' => 1, 'remark' => '己审核，请注意查收'));
        if ($res) {
            M('account_total_log')->where(array('user_id' => $list['user_id']))->setInc('tk_money_total', $list['money']);
            $this->success("确认成功");
        } else {
            $this->error("确认失败");
        }
    }

    //删除提现记录
    public function tikuan_del() {
        $id = I('id', '');
        $res = M('withdrawals')->delete($id);
        if ($res) {
            $this->success("删除成功!");
        } else {
            $this->error("删除失败 请重新操作!");
        }
    }


    //占比
    public function proportion() {
            $sql = "SELECT sum(user_money)as user_money,sum(zuce_money)as zuce_money,sum(pay_points)as pay_points,sum(share_points)as share_points ";
        $sql .= "FROM __PREFIX__account_log";

        $res = M()->cache(true)->query($sql);

//库存总单数累计
        $sql2 = "SELECT count(order_id) as num from  __PREFIX__bd_order";
        $sql_hk = "SELECT count(order_id) as num from  __PREFIX__bd_order where pay_name='汇款'";
        $sql_dz = "SELECT count(order_id) as num from  __PREFIX__bd_order where pay_name='电子积分'";
        $sql_tx = "SELECT sum(money) as amount from  __PREFIX__withdrawals where status=1";
          $bd_num = M()->cache(true)->query($sql2);
          $hk_num = M()->cache(true)->query($sql_hk);
          $dz_num = M()->cache(true)->query($sql_dz);
          $tx = M()->cache(true)->query($sql_tx);
        $this->assign('res',$res[0]);
        $this->assign('bd_num',$bd_num[0]);
        $this->assign('hk_num',$hk_num[0]);
        $this->assign('dz_num',$dz_num[0]);
        $this->assign('tx',$tx[0]);
        $this->display();
    }

}
